import { createStore } from 'vuex'
import createPersistedstate from 'vuex-persistedstate'

import user from './modules/user'
import cart from './modules/cart'
import category from './modules/category'

// 创建vuex仓库并导出
const store = createStore({
  state: {
    // 数据
    profile: {
      username: '展',
      age: 18
    }
  },
  mutations: {
    // 改数据函数
    setProfile (state, payload) {
      // console.log(state)
      state.profile.username = payload
    }
  },
  actions: {
    // 请求数据函数
  },
  modules: {
    // 分模块
    user,
    cart,
    category
  },
  // VueX 插件配置项
  plugins: [
    // 持久化存储插件
    createPersistedstate({
      key: 'erabbit-client-pc-store-65',
      paths: ['user', 'cart']
    })
  ]
})

export default store
